<template>

</template>

<script>
	import {
		getunReadMsg
	} from '@/api/api.js';
	export default {
		name: 'newmsg',
		props:['newmsg','message'],
		data() {
			return {
				timer:'',
			}
		},
		mounted(options) {
			this.starNewmsg()
		},
		methods: {
			clearInterval(){
				console.log(999)
				clearInterval(this.timer)
			},
		   starNewmsg() {
				let _this = this
				this.timer = setInterval(function() {
					let userInfo = uni.getStorageSync('userInfo') || ''
					if (userInfo?.id && _this.newmsg) {
						let route = getCurrentPages()
						getunReadMsg({}).then(r => {
							if (r.data.code == 200) {
								let count = parseInt(r.data.data.shensu) + parseInt(r.data.data.system) +parseInt(r.data.data.admin)
								if (count > 0) {
									uni.setTabBarBadge({
										index: 2,
										text: "" +count+ ""
									})
									if(_this.message){
										_this.$emit("backData",r.data.data);
									}
								} else {
									try {
										uni.removeTabBarBadge({
											index: 2,
											complete: {}
										})
									} catch (e) {
										console.log(e)
									}

								}
							}
						})
					} else {
						clearInterval(this.timer)
					}
				}, 5000)
			}


		}
	}
</script>